package meituan;

import java.util.Scanner;

public class Problem4Plus {
    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int arr[] = new int[n];
        for (int i = 0; i < n; i++) {
            arr[i] = sc.nextInt();
        }
        int dp[][][] = new int[n][n][n];

        for (int i = 1; i <= n; i++) {
            //区间长度
            for (int j = 0; j <= n - i; j++) {
                //区间起始点
                for (int k = j; k < j + i; k++) {
                    //分割点
                    int lm = Integer.MAX_VALUE, rm = Integer.MAX_VALUE, max = Integer.MAX_VALUE;
                    for (int m = j; m < k; m++) {
                        lm = Math.min(lm, dp[j][k - 1][m] + arr[k] * arr[m]);
                    }
                    for (int f = k + 1; f < j + i; f++) {
                        rm = Math.min(rm, dp[k + 1][j + i - 1][f] + arr[k] * arr[f]);
                    }
                    if (lm == max && rm == max) {
                        dp[j][j + i - 1][k] = 0;
                    } else if (lm == max) {
                        dp[j][j + i - 1][k] = rm;
                    } else if (rm == max) {
                        dp[j][j + i - 1][k] = lm;
                    } else {
                        dp[j][j + i - 1][k] = lm + rm;
                    }
                }
            }
        }
        int ans = Integer.MAX_VALUE;
        for (int i = 0; i < n; i++) {
            ans = Math.min(ans, dp[0][n - 1][i]);
        }
        System.out.println(ans);
    }
}
